﻿<div style="width: 380px; height: 350px;">
    <div class="modal-header">
        <a data-dismiss="modal" class="close" href="javascript:$.fancybox.close();">×</a>
        <h3>
            手机绑定</h3>
    </div>
    <div style="padding: 15px;">
        <div class="input-append" id="step-1">
            <input class="span3" type="text" id="mobile" name="mobile" maxlength="11" placeholder="请输入您有效的手机号码">
            <button class="btn" type="button" onclick="getSmsCode();">
                获取短信验证码
            </button>
        </div>
        <div class="input-append hide" id="step-2">
            <input class="span3" type="text" id="smscode" name="smscode" maxlength="6" placeholder="请输入手机短信验证码">
            <button class="btn" type="button" onclick="bindingMobile();">
                绑定该手机号码
            </button>
        </div>
        <p id="help-binding" class="help-block">
            请输入您有效的手机号码！
        </p>
        <div id="">
        </div>
    </div>
</div>
<script type="text/javascript">
    function getSmsCode() {
        var mobile = $('#mobile').val();
        if (!mobile.isMobile()) {
            $('#help-binding').html("请输入您有效的手机号码！");
        } else {
            $.postJSON('/security/smscode', { mobile: mobile }, function (result) {
                if (result.Status == true) {
                    $("#step-1").hide();
                    $("#step-2").show();
                    $('#help-binding').html("请输入手机短信验证码！");
                } else {
                    $('#help-binding').html(result.Message);
                }
            });
        }
    }
    function bindingMobile() {
        var mobile = $('#mobile').val();
        var smscode = $('#smscode').val();

        if (!mobile.isMobile()) {
            $('#help-binding').html("请输入正确的手机号码！");
            return;
        }
        if (smscode.isEmpty()) {
            $('#help-binding').html("请输入手机短信验证码！");
            return;
        }
        $.postJSON('/security/mobilebinding', { mobile: mobile, smscode: smscode }, function (result) {
            if (result.Status == true) {
                $("#step-1").hide();
                $("#step-2").show();
            } else {
                $('#help-binding').html(result.Message);
            }
        });
    }
</script>
